package com.example.recruitment_website.controller;

import com.example.recruitment_website.domain.User;
import com.example.recruitment_website.domain.Wine;
import com.example.recruitment_website.service.WineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("Wine")
public class WineController {
    @Autowired
    WineService wineService;

    @GetMapping("/findWineInfo")
    public HashMap findRecordById(){
        Pageable pageable = PageRequest.of(0,9);
        Page<Wine> list = wineService.findAll(pageable);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加成功");
        map.put("data",list);
        map.put("code",1);
        return map;
    }
    @GetMapping("/findAllBySort")
    public HashMap findAllBySort(String sort){
        PageRequest pageRequest = PageRequest.of(0,9);
        Page<Wine> list = wineService.findAllBySort(pageRequest,sort);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加成功");
        map.put("data",list);
        map.put("code",1);
        return map;
    }
    @GetMapping("/findByKey")
    public HashMap findByKey(String key){
        PageRequest pageRequest = PageRequest.of(0,9);
        Page<Wine> list = wineService.findByKey(pageRequest,key);
        HashMap<String,Object> map = new HashMap<>();
        map.put("msg","添加成功");
        map.put("data",list);
        map.put("code",1);
        return map;
    }

}
